package com.yiren.manager.components;

import com.mangofactory.swagger.configuration.SpringSwaggerConfig;
import com.mangofactory.swagger.models.dto.ApiInfo;
import com.mangofactory.swagger.plugin.EnableSwagger;
import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin;

import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Swagger配置
 * 
 * @author 冯胜德
 */
@Configuration
@EnableSwagger
public class SwaggerConfig {

	private SpringSwaggerConfig springSwaggerConfig;

	/**
	 * 读配置文件
	 */
	@Autowired
	private Properties swaggerProps;

	public Properties getSwaggerProps() {
		return swaggerProps;
	}

	public void setSwaggerProps(Properties swaggerProps) {
		this.swaggerProps = swaggerProps;
	}

	@Autowired
	public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
		this.springSwaggerConfig = springSwaggerConfig;
	}

	@Bean
	public SwaggerSpringMvcPlugin customImplementation() {
		return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(apiInfo()).includePatterns(".*?");
	}

	private ApiInfo apiInfo() {
		String title = swaggerProps.getProperty("swagger.title");
		String description = swaggerProps.getProperty("swagger.description");
		String terms = swaggerProps.getProperty("swagger.terms");
		String email = swaggerProps.getProperty("swagger.email");
		String licence = swaggerProps.getProperty("swagger.licence");
		String url = swaggerProps.getProperty("swagger.licence.url ");

		ApiInfo apiInfo = new ApiInfo(title, description, terms, email, licence, url);
		return apiInfo;
	}
}
